package club.caihappy.Condition;

import club.caihappy.pojo.RainBow;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Created by DELL on 2021/10/5
 **/
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean red = registry.containsBeanDefinition("club.caihappy.pojo.Red");
        boolean blue = registry.containsBeanDefinition("club.caihappy.pojo.Blue");
        if (red && blue) {
            //指定Bean定义信息;(Bean的类型，Bean...)
            RootBeanDefinition beanDefinition = new RootBeanDefinition(RainBow.class);
            //注册一个Bean，指定Bean名
            registry.registerBeanDefinition("rainBow",beanDefinition);
        }
    }
}
